<?php
/**
 * Created by PhpStorm.
 * User: changshuiwang
 * Date: 2016/7/8
 * Time: 10:55
 */
namespace common\models;

use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;

/**
 * User model
 *
 * @property integer $id
 * @property string $username
 * @property integer $score
 */
class Student extends ActiveRecord
{
    /**
     *
     * 根据id删除
     *
     * @param int $id 学生id
     *
     * @return boolean
     */
    public static function deleteById($id)
    {
        $student=Student::findOne($id);
        $student->tag=0;
        return $student->save();
    }

    /**
     * 
     * 
     */
    public function findById($id)
    {
        return Student::findOne([
            'id'=>$id
        ]);
    }
    /**
     * 
     */
    public static function modifyStudent($updateform)
    {
        //$test=new Student();
        $student=Student::findOne(['id'=>$updateform->id]);
        $student->username=$updateform->username;
        //$student->score=$updateform->score;
        $student->photo=$updateform->photo;
        return $student->save();
    }
    /**
     *
     */
    public static function addStudent($updateform)
    {
        $test=new Student();
        $test->username=$updateform->username;
        //$test->score=$updateform->score;
        $test->photo=$updateform->photo;
        return $test->save();

    }
    /**
     *
     */
    public static function filterStudent($username,$score,$tag)
    {
        $username=$username==null?"username=1 or true":"username='".$username."'";
        switch ($score){
            case '0':
                $score="score=1 or true";break;
            case 'a':
                $score="score<60";break;
            case 'b':
                $score="score>=60 and score<70";break;
            case 'c':
                $score="score>=70 and score<80";break;
            case 'd':
                $score="score>=80 and score<90";break;
            case 'e':
                $score="score>=90 and score<100";break;
        }

        switch($tag){
            case '0':
                $tag="true";break;
            case '1':
                $tag="tag=0";break;
            case '2':
                $tag="tag=1";break;
        }
        $result=Student::find()
            ->where("$username")
            ->andWhere("$score")
            ->andWhere("$tag");
        return $result;
    }
}